<?php
// 日志级别 0为不输出 E_ALL输出所有
error_reporting(E_ALL);
/*调用实例*/
require_once("db_class.php"); //引入数据库类文件
/*实例化类：*/

function wow($type,$name)
{
		$db=new mysql("127.0.0.1","zangyin","gunnimade","logon","conn","utf8");
/* 		if(!is_numeric($name))
		{
			echo "是字符串";
			exit;
		} */
		switch($type)
		{
//------------------------------------------------------------------------------------------------------------
			case 'online':
				//$sql = mysql_query("select a.id,a.last_ip,b.name from realmd.account a left join characters.characters b on a.id = b.account where b.online = '0'");
				$db->select_db("chars");
				$sql = mysql_query("SELECT account,name FROM `characters` WHERE `online` = '1' ORDER BY `account`");
				if(!$sql)
				{
					echo "没有玩家在线!";
					exit;
				}
				else
					{
						while($row=mysql_fetch_array($sql))
						{
							echo $row['account']."&nbsp;&nbsp;&nbsp;".$row['name'];
							echo "<br>";
						}
						printf("游戏在线人数: %d\n", mysql_affected_rows());
						
					}
					break;
//------------------------------------------------------------------------------------------------------------
			case 'banaccount':
				$sql = mysql_query("select id,last_ip from account where id = '".$name."'");
				if(!$sql)
				{
					echo "没有玩家在线!";
					exit;
				}
				else
					{
					while($row=mysql_fetch_array($sql))
						{
							if(!$db->replace('account_banned','id',$row['id']))
							{
								echo $row['id']."&nbsp;&nbsp;账户已经被封!<br>";
							}
							else
							{
								echo "封号失败.速度联系我!<br>";
							}

							if(!$db->replace('ip_banned','ip,bandate','"'.$row['last_ip'].'","0"'))
							{
								echo $row['last_ip']."&nbsp;&nbsp;IP已经被封!";
							}
							else
							{
								echo "封ip失败,速度联系我!";
							}
						}
					}
					break;
//------------------------------------------------------------------------------------------------------------
			case 'delbanaccount':
				$sql = mysql_query("select id,username from account where username = '".$name."'");
				if(!$sql)
				{
					echo "这个账户没有被封!";
					exit;
				}
				else
					{
						while($row=mysql_fetch_array($sql))
						{
							if($db->delete("account_banned","id = '".$row['id']."'"))
							{
								echo "这个账户没有被封!";
							}
							else
							{
								echo "账户ID:".$row['id']."&nbsp;&nbsp;&nbsp;<br>账户:".$row['username'];
							}
						}
						
					}
					break;
//------------------------------------------------------------------------------------------------------------
			case 'delbanip':
				$sql = mysql_query("select last_ip from account where last_ip = '".$name."'");
				if(!$sql)
				{
					echo "这个IP没有被封!";
					exit;
				}
				else
					{
						while($row=mysql_fetch_array($sql))
						{
							if($db->delete("ip_banned","ip = '".$row['last_ip']."'"))
							{
								echo "11";
							}
							else
							{
								echo "账户Ip:".$row['last_ip']."已经被解封了!<br>";
							}
						}
						
					}
					break;

		}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE>Welcome</TITLE>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>
 <BODY>
<form name="input" action="test.php" method="get">
<input type="text" name="name" />
<select name="type" class="textarea">
<option selectd value="online">人数</option>
<option value="banaccount">封号</option>
<option value="delbanaccount">解号</option>
<option value="delbanip">解IP</option>
<input type="submit" value="执行" />
</form>
<?
if(isset($_GET['name']) && isset($_GET['type']))
{
	$name =$_GET['name'];
	$type =$_GET['type'];
	wow($type,$name);
}
else
{
	echo "Welcome!";
}
?>
 </BODY>
</HTML>